package main

import (
	"fmt"
	"time"
)

var (
	sema     = make(chan struct{}, 1)
	balance2 int
)

func Deposit2(amount int) {
	sema <- struct{}{}
	balance2 = balance2 + amount
	<-sema
}

func Balance2() int {
	sema <- struct{}{}
	b := balance2
	<-sema
	return b
}

func main1() {
	go Deposit2(100)
	go Deposit2(200)
	go Deposit2(300)
	go Deposit2(300)
	time.Sleep(1 * time.Second)
	fmt.Println(Balance2())
}
